package org.scohen.juploadr.uploadapi.abilities;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import org.scohen.juploadr.app.PhotoSet;
import org.scohen.juploadr.util.NonNullList;

public class OrganizeAbilities implements AbilitiesList {
    private boolean hasPhotoSets = true;
    private NonNullList<PhotoSet> photoSets = new NonNullList<PhotoSet>();
    private OrganizeAbilityNotification notification;

    public boolean hasPhotoSets() {
        return hasPhotoSets;
    }

    public boolean allDisabled() {
        return !hasPhotoSets;
    }

    public void notified(AbilityNotification n) {
        notification = (OrganizeAbilityNotification) n;
        if (!notification.getPhotoSets().isEmpty()) {
            if (notification.shouldReplaceOldSets()) {
                photoSets.clear();
            }
           
            photoSets.addAll(notification.getPhotoSets());

            Collections.sort(photoSets, new Comparator<PhotoSet>() {
                public int compare(PhotoSet o1, PhotoSet o2) {
                    return o1.getTitle().compareToIgnoreCase(o2.getTitle());
                }
            });
            
        }

    }

    public List<PhotoSet> getPhotoSets() {
        return photoSets;
    }

}
